import alert from '../alert-ui.vue'
let $vm;
export default  {
    install(Vue, option = {
        title: "温馨提示",
        btnTitle: "确定"
    }){

        if (!$vm) {
            const Alert = Vue.extend(alert);
            $vm = new Alert({
                el: document.createElement('div')
            });
            document.body.appendChild($vm.$el);
        }
        Vue.$alert = {
            show({content = "", title = "温馨提示", btnTitle = "确定"} = {}) {
                this.alertShow(title, content, btnTitle);
            },
            text(content = "", title = option.title, btnTitle = option.btnTitle){
                this.alertShow(content, title, btnTitle);
            },
            alertShow(content = "", title = option.title, btnTitle = option.btnTitle){
                $vm.isShow = true;
                $vm.title = title;
                $vm.content = content;
                $vm.btnTitle = btnTitle;
            },
            hide() {
                $vm.isShow = false;
            }
        }
        Vue.mixin({
            created() {
                this.$alert = Vue.$alert;
            }
        })
    }
}